<?php
   class Product extends MY_Controller{
	   public function __construct(){
		   parent::__construct();
		   $this->load->helper("url");
		   $this->load->model("mpro");
	   }
	  public function index(){
		   $segment_1 = (int)$this->uri->segment(2);
		   $id = array_pop(explode('-', $segment_1));
		   $segment_2 = (int)$this->uri->segment(3);
		   $start = array_pop(explode('-', $segment_2));
		   $action = array("trang");	
		   $getVar = $this->uri->uri_to_assoc(1, $action);
		   $config['base_url'] = base_url()."san-pham/".$getVar['san-pham']."";
		   $config['total_rows'] = $this->mpro->count_all($id);
		   $config['per_page'] = 12;
		   $config['uri_segment'] = 3;
		   $config['next_link'] = "Next";
		   $config['prev_link'] = "Prev";
		   $this->load->library("pagination",$config);
		   $data['menu'] = $this->menu();
		   $data['menuintro'] = $this->menu_intro();
		   $data['menustreng'] = $this->menu_streng();
		   $data['menukt'] = $this->menu_kt();
		   $data['support'] = $this->support();			   
		   $data['results'] = $this->mpro->listall($id,$config['per_page'],$start);
		   $ok = $this->mpro->getcate($id);
		   $data['title'] = $ok['cate_name'];
		   $this->load->view("products/layout",$data);
	   }
	   public function all(){
		    $this->load->model("mpro");
		   $id = $this->uri->segment(4);
		   $config['base_url'] = base_url().'home/product/all/';
		   $config['total_rows'] = $this->mpro->count_al();
		   $config['per_page'] = 12;
		   $config['uri_segment'] = 4;
		   $config['next_link'] = "Next";
		   $config['prev_link'] = "Prev";
		   $this->load->library("pagination",$config);
		   $start = $this->uri->segment(4);
		   $data = $this->news_ty(); 
		   $data['menu'] = $this->menu();
		   $data['mn'] = $this->menu_top();
		   $data['results'] = $this->mpro->listal($config['per_page'],$start);
		   $data['title'] = "Hoa vip";
		   $this->load->view("products/hv/layout",$data);
	   }
	   public function view(){
		   $this->load->model("mpro");
		   $id = (int)$this->uri->segment(4);
		   $data['menu'] = $this->menu();
		   $data['menuintro'] = $this->menu_intro();
		   $data['menustreng'] = $this->menu_streng();
		   $data['menukt'] = $this->menu_kt();
		   $data['support'] = $this->support();			   
		   $data['detail'] = $this->mpro->detail($id);
		   if($data['detail'] == NULL){
			   	redirect(base_url());
				exit();
		   }
		   $data['results'] = $this->mpro->splq($data['detail']['cate_id'],$id);
		   $data['title'] = $data['detail']['pro_name'];
		   $this->load->view("products/detail/layout",$data);
	   }
   }